package com.android.qjpmc.application_module.station.fragment;

import android.graphics.Color;

import com.android.qjpmc.data_module.AnalogDataItem;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import java.util.ArrayList;
import java.util.List;

//模拟量曲线
class JCAnalogCurve
{
    public LineDataSet data_set = null;
    List<Entry> entries = new ArrayList<>();
    public AnalogDataItem data_item = null;
};

public class JCAnalogCurveSet
{
    ArrayList<JCAnalogCurve> m_CurveSet = new ArrayList<>();
    ArrayList<ILineDataSet> m_line_data_sets = new ArrayList<ILineDataSet>();
    int m_last_curve_idx = 0;

    ArrayList<ILineDataSet> GetLineDataSets()
    {
        return m_line_data_sets;
    }
    public int GetCurveCount()
    {
        return m_CurveSet.size();
    }
    //增加曲线
    public int AddCurve(AnalogDataItem DataItem, int Color)
    {

        if (IsCurveExist(DataItem) != null)
        {
            return 1;
        }
        JCAnalogCurve the_curve = new JCAnalogCurve();
        the_curve.data_set = new LineDataSet(the_curve.entries, DataItem.m_Name);
        the_curve.data_set.setColors(GetColor(m_last_curve_idx));
        the_curve.data_item = DataItem;
        m_last_curve_idx++;
        m_line_data_sets.add(the_curve.data_set);
        m_CurveSet.add(the_curve);
        return 0;
    }
    public JCAnalogCurve IsCurveExist(AnalogDataItem DataItem)
    {
        if (m_CurveSet == null)
        {
            return null;
        }
        for (JCAnalogCurve curve: m_CurveSet)
        {
            if (curve.data_item == DataItem)
            {
                return curve;
            }
        }
        return null;
    }
    //移除曲线
    public int RemoveCurve(AnalogDataItem DataItem)
    {
        JCAnalogCurve curve = IsCurveExist(DataItem);
        if (curve == null)
        {
            return 1;
        }
        m_CurveSet.remove(curve);
        m_line_data_sets.remove(curve.data_set);
        curve = null;
        return 1;
    }
    ArrayList<ILineDataSet> CreateDataSets()
    {
        m_line_data_sets.clear();
        for (JCAnalogCurve curve: m_CurveSet)
        {
            m_line_data_sets.add(curve.data_set);
        }
        return m_line_data_sets;
    }
    /*
    @ColorInt public static final int DKGRAY      = 0xFF444444;
    @ColorInt public static final int GRAY        = 0xFF888888;
    @ColorInt public static final int LTGRAY      = 0xFFCCCCCC;
    @ColorInt public static final int WHITE       = 0xFFFFFFFF;
    @ColorInt public static final int RED         = 0xFFFF0000;
    @ColorInt public static final int GREEN       = 0xFF00FF00;
    @ColorInt public static final int BLUE        = 0xFF0000FF;
    @ColorInt public static final int YELLOW      = 0xFFFFFF00;
    @ColorInt public static final int CYAN        = 0xFF00FFFF;
     */

    int GetColor(int idx)
    {
        int color = Color.BLACK;
        switch(idx%6)
        {
            case 0:
            {
                color = Color.YELLOW;
            }
            break;
            case 1:
            {
                color = Color.GREEN;
            }
            break;
            case 2:
            {
                color = Color.RED;
            }
            break;
            case 3:
            {
                color = Color.BLUE;
            }
            break;
            case 4:
            {
                color = Color.LTGRAY;
            }
            break;
            case 5:
            {
                color = Color.CYAN;
            }
            break;
            default:
            {

            }
        }
        return color;
    }
    public void clear()
    {
        m_CurveSet.clear();
    }
}
